class UserController < ApplicationController
  before_filter :login_required, :only => :my_account
  before_filter :chk_logged_in, :only => :login

  def login
    @user=Users.new
    @user.username=params[:username]
  end

  def process_login
    if user = Users.authenticate(params[:user])
      session[:id] = user.id # Remember the user's id during this session
      redirect_to :controller=> 'task',:action => 'list'
      #redirect_to session[:return_to] || '/user/my_account'
    else
      flash[:error] = 'Invalid login.'
      redirect_to :action => 'login', :username => params[:user][:username]
    end
  end

  def logout
    reset_session
    flash[:message] = 'You are Logged out.'
    redirect_to :action => 'login' 
  end

  def my_account
    redirect_to :controller=>"task",:action => "list"
  end

end
